﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using DTO;

namespace QuanLyCuaHangVideo
{
    public partial class frmDangNhap : Form
    {
        public event FireEventForLoginSuccess FireEventLoginSuccess = null;
        
        public frmDangNhap()
        {
            InitializeComponent();
        }

        private void DangNhap()
        {
            NhanVien kq = new NhanVien();
            kq = NhanVienDAO.IsExisting(txtTenDangNhap.Text, txtMatKhau.Text);
            if (kq != null)
            {
                FireEventLoginSuccess(this, new LoginSuccessEventArgs { HoTen = kq.HoTen, LoaiNV = kq.LoaiNV.ToString() });
                Close();
            }
            else
            {
                MessageBox.Show("Tài khoản hoặc mật khẩu không đúng!");
            }
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            DangNhap();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        //sau khi dien password xong va nhan enter 
        private void txtMatKhau_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                DangNhap();
            }
        }
    }
}
